package com.webdemo05.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import com.webdemo05.pojo.User;
import com.webdemo05.util.HibernateHandler;

public class DeleteUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public DeleteUser() {
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("id");
		Session session  = HibernateHandler.newInstance().getCurrentSession();
		session.beginTransaction();
		User user = (User)session.load(User.class,Integer.parseInt(id));
		session.delete(user);
		session.getTransaction().commit();
		response.sendRedirect(this.getServletContext().getContextPath()+"/QueryUser");
	}
}
